<script type="text/javascript">
<!--
$(function() {
	$( "#ngay" ).datepicker({
								showOtherMonths: true,
								selectOtherMonths: true,
								changeMonth: true,								
								dateFormat: "dd-mm-yy",
								showOn: "both",
								buttonImage:$('#root').val()+"img/calendar.jpg",
								buttonImageOnly: true
	 							});
	$("#ngaybd,#ngaykt").keydown(function(e) {
        if ( e.keyCode != 13) {}
        else 
            {
                e.preventDefault(); 
            }   
        }
    );

	$(".soluong").keydown(function(e) {
		arr_key = new Array();
		arr_key[8]=8;
		arr_key[9]=9;
		arr_key[35]=35;
		arr_key[36]=36;
		arr_key[37]=37;
		arr_key[39]=39;
		arr_key[46]=46;
        if ( arr_key[e.keyCode]!==undefined) {}
        else {
            if (e.keyCode < 48 || e.keyCode > 57 ) {
                e.preventDefault(); 
            }   
        }});
});
	
//-->
</script>
<div class="index">
<?php
	echo $form->create('Chitieungay',array('url'=>array('action'=>'nhapkqbanhang',$nhanvien_id)));
	echo $form->input('root',array('id'=>'root','type'=>'hidden','value'=>$this->webroot)); 
?>
<table>
<tr>
<td><?php echo $form->input('ngay',array('id'=>'ngay','type'=>'text','label'=>'Ngày','style'=>'width: 70px; height:20px','value'=>$ngay))?></td>
</tr>
</table>
<div id='kehoach' >
<?php
if(!empty($chitieungays) && !empty($hanghoas))
{
$numhh = count($hanghoas); 
?>

<h2 style="text-align:center">Nhập kết quả bán hàng lưu động</h2>
<!--<h3>Ngày <?php echo date('d-m-Y',strtotime($ngay));?></h3-->


<table id ='tables'>
<tr>
<th rowspan=2>STT</th>
<th rowspan=2>Đội</th>
<th rowspan=2>Địa Điểm</th>
<th rowspan=2>Ngày</th>
<th rowspan=2>Thành viên tham gia</th>
<th colspan=<?php echo $numhh?>>Kết Quả</th>
<th rowspan=2>Ghi chú</th>
</tr>
<tr>
<?php foreach ($hanghoas as $keyhh =>$valhh):?>
<th><?php echo $valhh ?></th>
<?php endforeach;?>
</tr>
<?php
	$i=0; 
	 foreach ($chitieungays as $chitieungay):
	  $i++;
?>
<tr>
<td><? echo $i?></td>
<?php echo $form->input('idkh',array('type'=>'hidden','value'=>$chitieungay['Kehoachbhld']['id']))?>
<?php echo $form->input('nhanvien_id',array('type'=>'hidden','value'=>$chitieungay['Kehoachbhld']['nhanvien_id']))?>
<td><?php echo $chitieungay['Kehoachbhld']['tendoi']?></td>
<td><?php echo $chitieungay['Kehoachbhld']['diadiem']?></td>
<td><?php echo date('d-m-Y',strtotime($chitieungay['Kehoachbhld']['thoigian']))?></td>
<td><?php echo $chitieungay['Kehoachbhld']['nhansu']?></td>
<?php foreach ($hanghoas as $keyhh =>$valhh):
		foreach ($chitieungay['Chitieungay'] as $ctngay)
		{
			if($ctngay['hanghoa_id']==$keyhh)
			{
				echo '<td><input class="soluong" name=data[Chitieungay][hanghoa]['.$ctngay['id'].'] value='.$ctngay['ketqua'].'></td>';
			}	
		}
	endforeach;?>
<td><?php echo $chitieungay['Kehoachbhld']['ghichu']?></td>
<?php endforeach;?>
</tr>
</table>
<?php echo $form->end('  Lưu  ');
}
else 
{
	echo "<h2>Không có kế hoạch BHLĐ ngày ".date('d-m-Y')."</h2>";
}
?>

</div>
</div>
<?php
$this->Js->get('#ngay')->event('change',
								$this->Js->request(array('controller' => 'chitieungays', 'action' => 'laykehoach',$nhanvien_id),
								array('update' => '#kehoach','async' => true,
								'dataExpression' => true,'method' => 'post',
								'data' => $js->serializeForm(array('isForm' => false, 'inline' => true))))); 
?>